package cn.kshost.zqyg.manager.controller;

import cn.kshost.zqyg.manager.service.ProductSpecService;
import cn.kshost.zqyg.model.entity.product.ProductSpec;
import cn.kshost.zqyg.model.vo.common.Result;
import cn.kshost.zqyg.model.vo.common.ResultCodeEnum;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/product/productSpec")
@Tag(name = "商品规格")
public class ProductSpecController {

    @Autowired
    ProductSpecService productSpecService;

    @Operation(summary = "查询所有规格")
    @GetMapping("/findAll")
    public Result<List<ProductSpec>> findAll() {
       List<ProductSpec> productSpecList =  productSpecService.findAll();
       return Result.build(productSpecList, ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "分页查询")
    @GetMapping("/{pageNum}/{pageSize}")
    public Result<PageInfo<ProductSpec>> getProductSpec(@PathVariable int pageNum , @PathVariable int pageSize ) {

        PageInfo<ProductSpec> pageInfo =   productSpecService.geyByPage(pageNum,pageSize);
        return Result.build(pageInfo, ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "商品规格添加")
    @PostMapping("/save")
    public Result save (@RequestBody  ProductSpec productSpec) {
        productSpecService.save(productSpec);

        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "商品规格修改")
    @PutMapping("/updateById")
    public Result updateById(@RequestBody ProductSpec productSpec) {

        productSpecService.updateById(productSpec);
        return  Result.build(null, ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "商品规格通过id删除")
    @DeleteMapping("/removeById/{id}")
    public  Result removeById(@PathVariable Long id) {

        productSpecService.removeById(id);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }



}
